home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / MySQLdb / connections.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  9.2 KB  |  199 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''MySQLdb Connections Module
  5.  
  6. This module implements connections for MySQLdb. Presently there is
  7. only one class: Connection. Others are unlikely. However, you might
  8. want to make your own subclasses. In most cases, you will probably
  9. override Connection.default_cursor with a non-standard Cursor class.
  10.  
  11. '''
  12. import cursors
  13. from _mysql_exceptions import NotSupportedError, ProgrammingError
  14.  
  15. class Connection:
  16.     '''Create a connection to the database. It is strongly recommended
  17.     that you only use keyword parameters. "NULL pointer" indicates that
  18.     NULL will be passed to mysql_real_connect(); the value in parenthesis
  19.     indicates how MySQL interprets the NULL. Consult the MySQL C API
  20.     documentation for more information.
  21.  
  22.     host -- string, host to connect to or NULL pointer (localhost)
  23.     user -- string, user to connect as or NULL pointer (your username)
  24.     passwd -- string, password to use or NULL pointer (no password)
  25.     db -- string, database to use or NULL (no DB selected)
  26.     port -- integer, TCP/IP port to connect to or default MySQL port
  27.     unix_socket -- string, location of unix_socket to use or use TCP
  28.     client_flags -- integer, flags to use or 0 (see MySQL docs)
  29.     conv -- conversion dictionary, see MySQLdb.converters
  30.     connect_time -- number of seconds to wait before the connection
  31.             attempt fails.
  32.     compress -- if set, compression is enabled
  33.     init_command -- command which is run once the connection is created
  34.     read_default_file -- see the MySQL documentation for mysql_options()
  35.     read_default_group -- see the MySQL documentation for mysql_options()
  36.     cursorclass -- class object, used to create cursors or cursors.Cursor.
  37.             This parameter MUST be specified as a keyword parameter.
  38.  
  39.     Returns a Connection object.
  40.  
  41.     There are a number of undocumented, non-standard methods. See the
  42.     documentation for the MySQL C API for some hints on what they do.
  43.     '''
  44.     default_cursor = cursors.Cursor
  45.     
  46.     def __init__(self, *args, **kwargs):
  47.         connect = connect
  48.         import _mysql
  49.         CLIENT = CLIENT
  50.         import constants
  51.         conversions = conversions
  52.         import converters
  53.         import types
  54.         kwargs2 = kwargs.copy()
  55.         if not kwargs.has_key('conv'):
  56.             kwargs2['conv'] = conversions.copy()
  57.         
  58.         if kwargs.has_key('cursorclass'):
  59.             self.cursorclass = kwargs['cursorclass']
  60.             del kwargs2['cursorclass']
  61.         else:
  62.             self.cursorclass = self.default_cursor
  63.         self._db = apply(connect, args, kwargs2)
  64.         self._db.converter[types.StringType] = self._db.string_literal
  65.         self._transactional = self._db.server_capabilities & CLIENT.TRANSACTIONS
  66.  
  67.     
  68.     def __del__(self):
  69.         if hasattr(self, '_db'):
  70.             self.close()
  71.         
  72.  
  73.     
  74.     def close(self):
  75.         '''Close the connection. No further activity possible.'''
  76.         self._db.close()
  77.  
  78.     
  79.     def begin(self):
  80.         '''Explicitly begin a transaction. Non-standard.'''
  81.         self._db.query('BEGIN')
  82.  
  83.     
  84.     def commit(self):
  85.         '''Commit the current transaction.'''
  86.         if self._transactional:
  87.             self._db.query('COMMIT')
  88.         
  89.  
  90.     
  91.     def rollback(self):
  92.         '''Rollback the current transaction.'''
  93.         if self._transactional:
  94.             self._db.query('ROLLBACK')
  95.         else:
  96.             raise NotSupportedError, 'Not supported by server'
  97.  
  98.     
  99.     def cursor(self, cursorclass = None):
  100.         '''Create a cursor on which queries may be performed. The
  101.         optional cursorclass parameter is used to create the
  102.         Cursor. By default, self.cursorclass=cursors.Cursor is
  103.         used.'''
  104.         if not cursorclass:
  105.             pass
  106.         return self.cursorclass(self)
  107.  
  108.     
  109.     def literal(self, o):
  110.         '''If o is a single object, returns an SQL literal as a string.
  111.         If o is a non-string sequences, the items of the sequence are
  112.         converted and returned as a sequence.'''
  113.         import _mysql
  114.         return _mysql.escape(o, self._db.converter)
  115.  
  116.     
  117.     def affected_rows(self):
  118.         return self._db.affected_rows()
  119.  
  120.     
  121.     def dump_debug_info(self):
  122.         return self._db.dump_debug_info()
  123.  
  124.     
  125.     def escape_string(self, s):
  126.         return self._db.escape_string(s)
  127.  
  128.     
  129.     def get_host_info(self):
  130.         return self._db.get_host_info()
  131.  
  132.     
  133.     def get_proto_info(self):
  134.         return self._db.get_proto_info()
  135.  
  136.     
  137.     def get_server_info(self):
  138.         return self._db.get_server_info()
  139.  
  140.     
  141.     def info(self):
  142.         return self._db.info()
  143.  
  144.     
  145.     def kill(self, p):
  146.         return self._db.kill(p)
  147.  
  148.     
  149.     def field_count(self):
  150.         return self._db.field_count()
  151.  
  152.     num_fields = field_count
  153.     
  154.     def ping(self):
  155.         return self._db.ping()
  156.  
  157.     
  158.     def row_tell(self):
  159.         return self._db.row_tell()
  160.  
  161.     
  162.     def select_db(self, db):
  163.         return self._db.select_db(db)
  164.  
  165.     
  166.     def shutdown(self):
  167.         return self._db.shutdown()
  168.  
  169.     
  170.     def stat(self):
  171.         return self._db.stat()
  172.  
  173.     
  174.     def string_literal(self, s):
  175.         return self._db.string_literal(s)
  176.  
  177.     
  178.     def thread_id(self):
  179.         return self._db.thread_id()
  180.  
  181.     
  182.     def _try_feature(self, feature, *args, **kwargs):
  183.         
  184.         try:
  185.             return apply(getattr(self._db, feature), args, kwargs)
  186.         except AttributeError:
  187.             raise NotSupportedError, 'not supported by MySQL library'
  188.  
  189.  
  190.     
  191.     def character_set_name(self):
  192.         return self._try_feature('character_set_name')
  193.  
  194.     
  195.     def change_user(self, *args, **kwargs):
  196.         return apply(self._try_feature, ('change_user',) + args, kwargs)
  197.  
  198.  
  199.